package onenet

import (
	"net/http"
	"time"

	https "gitee.com/injoyai/goutil/net/http"
)

func New(apiKey string, fn func(*Back) error) *Option {
	return &Option{
		Http: https.NewClient(func(i https.Interface) {
			i.SetTimeout(time.Second * 30)
			i.AddHead("api-key", apiKey)
			i.Debug()
		}),
		FnBack: fn,
	}
}

//回调处理
func (this *Option) Handler(w http.ResponseWriter, r *http.Request) {
	this.handler(w, r)
}

//获取设备详情
//@pid,平台id
func (this *Option) Get(pid string) (Device, error) {
	return this.get(pid)
}

//注册设备,imsi可以和imei一样
//@imei,设备imei号
func (this *Option) Create(imei string) (string, error) {
	return this.create(imei, imei)
}

//删除设备
//@pid,平台id
func (this *Option) Delete(pid string) error {
	return this.delete(pid)
}

//设备通讯
//@imei,设备imei号
//@order,命令内容
func (this *Option) Send(imei, order string) error {
	return this.send(imei, order)
}
